<template>
  <div>
    <a-card :bordered="false">
      <f-search-form @searchHandler="searchHandler">
        <f-search-form-item label="项目代码" name="projectCode" slot="advanced"/>
        <f-search-form-item label="项目名称" name="projectName"/>
        <f-search-form-item label="专业代码" name="majorCode" slot="advanced"/>
        <f-search-form-item label="专业名称" name="majorName"/>
        <f-search-form-item label="工程包代码" name="packageNo" slot="advanced"/>
        <f-search-form-item label="工程包名称" name="packageName"/>
      </f-search-form>
      <f-table ref="table" rowKey="materialPackage100Id" :showSetting="true" :tableColumns="columns" tableName="bmpIndex" :exportBtn="false"
               :multiple="false"
               :operator="operator" :params="queryParam" :api="api.bmp" handler="materialPackagePageListHandler">
        <span slot="projectCode" slot-scope="text, record">
            <a-tag color="#108ee9" @click="$refs.bmpBaseDrawer.showDrawer(record)">{{text}}</a-tag>
        </span>
        <span slot="action" slot-scope="text, record">
          <template>
            <a @click="$refs.detailsDrawer.showDrawer(record)">查看详情</a>
            <a-divider type="vertical"/>
            <a @click="editSupplier(record)">编辑供应商</a>
          </template>
        </span>
      </f-table>
      <bmp-drawer ref="drawer"></bmp-drawer>
      <bmp-details-drawer ref="detailsDrawer"></bmp-details-drawer>
      <bmp-base-drawer ref="bmpBaseDrawer"></bmp-base-drawer>
    </a-card>
    <div v-if="visible">
      <a-modal
        title="项目转存200"
        :visible="visible"
        :confirm-loading="confirmLoading"
        @ok="handleOk"
        @cancel="handleCancel"
      >
        <span>项目名称：</span>
        <a-select style="width: 400px" showSearch optionFilterProp="children" @change="valueChange">
          <a-select-option v-for="item in projectList" :key="item.projectId" :value="item.projectId">
            {{ item.projectName }}
          </a-select-option>
        </a-select>
      </a-modal>
    </div>
  </div>
</template>
<script>
  import bmpDrawer from './bmp_drawer.vue'
  import bmpDetailsDrawer from './bmp_details_drawer.vue'
  import bmpBaseDrawer from './bmp_base_drawer.vue'
  import api from './js/api'

  export default {
    name: 'TableList',
    components: {
      bmpDrawer, bmpDetailsDrawer, bmpBaseDrawer
    },
    data() {
      let me = this
      //操作按钮
      let operator = []
      operator.push({
        name: '转存200',
        that: this,
        handler: function(table, that) {
          that.visible = true
        }
      })
      return {
        api: Object.assign(api, this.api),
        //列表初始化查询参数
        queryParam: { isGroup: true },
        visible: false,
        confirmLoading: false,
        projectId: '',
        projectList: [],
        // 表头
        columns: [
          {
            title: '序号',
            width: '60',
            align: 'center',
            dataIndex: '#',
            customRender: (text, record, index) => index + 1
          },
          {
            title: '项目代码',
            align: 'center',
            dataIndex: 'projectCode',
            scopedSlots: { customRender: 'projectCode' }
          },
          {
            title: '项目名称',
            align: 'center',
            dataIndex: 'projectName'
          },
          {
            title: '工程包名称',
            align: 'center',
            dataIndex: 'packageName'
          },
          {
            title: '工程包代码',
            align: 'center',
            dataIndex: 'packageNo'
          },
          {
            title: '专业名称',
            align: 'center',
            dataIndex: 'majorName'
          },
          {
            title: '专业代码',
            align: 'center',
            dataIndex: 'majorCode'
          },
          {
            title: '最近一次版本提交时间',
            align: 'center',
            dataIndex: 'updateTime'
          },
          {
            title: '操作',
            align: 'center',
            dataIndex: 'action',
            scopedSlots: { customRender: 'action' }
          }
        ],
        operator: operator
      }
    },
    created() {
      this.getProjectList()
    },
    methods: {
      valueChange(val) {
        this.projectId = val
      },
      handleOk(e) {
        this.confirmLoading = true
        setTimeout(() => {
          this.archive200()
        }, 2000)
      },
      handleCancel(e) {
        this.visible = false
      },
      getProjectList() {
        this.http.get(this, {
          url: this.api.bmp.projectList,
          data: {},
          success(me, data) {
            me.projectList = data
          }
        })
      },
      archive200() {
        this.visible = false
        this.confirmLoading = false
        let that = this
        that.http.post(that, {
          url: that.api.bmp.archive200,
          data: {
            projectId: this.projectId
          },
          success(me, data) {
            me.$message.success(data)
          }
        })
      },
      editSupplier(record) {
        this.http.get(this, {
          url: this.api.project.projectStatus,
          data: {
            projectId: record.projectId
          },
          success: function(me, data) {
            let projectStatus = data
            if (projectStatus == 1) {
              me.$message.error('项目已锁定不支持操作')
            } else {
              me.$refs.drawer.showDrawer(record)
            }
          }
        })
      }
    }
  }
</script>
